﻿// 麻省理工学院许可证
//
// 版权所有 (c) 2023-2025 缄默 联系电话/18521355630 
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

namespace LvcChong
{
    public class UltraGridHelper
    {
        public static void InitializeUltraGridDisplay(UltraGrid grid, List<UltraGridDisplayItem> displayItems, bool setDefaultStyle = false, UltraGridOptions ultraGridOptions = null!)
        {
            if (setDefaultStyle) SetGridDefaultStyle(grid, ultraGridOptions);

            foreach (var item in grid.DisplayLayout.Bands)
            {
                InitializeUltraGridBandDisplay(item, displayItems, ultraGridOptions);

                item.Override.CellPadding = 5;
            }

            ApplyGridOptions(grid, ultraGridOptions);
        }

        public static void ApplyGridOptions(UltraGrid grid, UltraGridOptions ultraGridOptions)
        {
            if (ultraGridOptions == null!) ultraGridOptions = new UltraGridOptions();

            if (ultraGridOptions.ShowSummary)
            {
                var band = grid.DisplayLayout.Bands[0];
                // 固定底部
                band.Override.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
                band.Override.SummaryValueAppearance.BackColor = Color.White;
                band.Override.BorderStyleSummaryValue = UIElementBorderStyle.None;
                band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
                band.Override.SummaryValueAppearance.BorderColor = Color.Transparent;
                band.Override.SummaryFooterAppearance.BorderColor = Color.Transparent;
                if (band.Columns.Count > 0)
                {
                    var s1 = band.Summaries.Add(SummaryType.Count, band.Columns[0]);
                    s1.DisplayFormat = "总数 = {0}";
                    s1.SummaryPosition = SummaryPosition.Left;
                    s1.Appearance.FontData.Bold = DefaultableBoolean.True;
                    s1.Appearance.FontData.Name = "微软雅黑";
                    s1.Appearance.FontData.SizeInPoints = 10;
                    s1.Appearance.ForeColor = Color.SteelBlue;
                    s1.Appearance.TextVAlign = VAlign.Middle;
                    s1.Lines = ultraGridOptions.ShowSummaryLines;
                }
            }

            foreach (var item in grid.DisplayLayout.Bands)
            {
                if (ultraGridOptions.EnableFixedHeader) item.RowLayoutStyle = RowLayoutStyle.None;
                if (ultraGridOptions.EnableCopy)
                {
                    grid.DoubleClickCell += (ss, ee) => { try { Clipboard.SetDataObject(ee.Cell.Text); } finally { } };
                }
            }

            var menu = new ContextMenuStrip();
            if (ultraGridOptions.EnableCopy)
            {
                var copy = menu.Items.Add("复制整行");
                copy.Click += (s, e) =>
                {
                    if (grid.ActiveRow == null) return;
                    grid.PerformAction(UltraGridAction.Copy, false, false);
                };

                var cellCopy = menu.Items.Add("复制单元格");
                menu.Opening += (s, e) =>
                {
                    if (grid.ActiveRow == null || grid.ActiveRow is UltraGridGroupByRow)
                    {
                        e.Cancel = true;
                        return;
                    }
                    var sub = cellCopy as ToolStripMenuItem;
                    sub.DropDownItems.Clear();

                    foreach (var cell in grid.ActiveRow.Cells.Cast<UltraGridCell>().OrderBy(x => x.Column.Header.VisiblePosition))
                    {
                        if (cell.Column.Hidden) continue;
                        var it = sub.DropDownItems.Add(cell.Column.Header.Caption);
                        it.MouseEnter += (ss, ee) =>
                        {
                            cell.Selected = true;
                        };
                        it.MouseLeave += (ss, ee) =>
                        {
                            cell.Selected = false;
                        };
                        it.Click += (ss, ee) =>
                        {
                            cell.Selected = false;
                            try
                            {
                                Clipboard.SetDataObject(cell.Text);
                            }
                            catch (Exception ex)
                            {
                                MessageHelper.ShowWarningBox("复制失败\r\n" + ex.Message);
                            }
                        };
                    }
                };
            }
            if (ultraGridOptions.EnableExport)
            {
                if (ultraGridOptions.EnableCopy)
                    menu.Items.Add("-");

                var exporter = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter(grid.Container);
                exporter.ExportValueLists = ultraGridOptions.ExportValueList;
                exporter.ExportFormulas = ultraGridOptions.ExportFormula;
                ultraGridOptions.InitialExport?.Invoke(exporter);
                var mnuExport = menu.Items.Add("导出到Excel");
                mnuExport.Click += (s, e) =>
                {
                    var processlist = Process.GetProcesses();
                    foreach (Process runningProcess in processlist.Where(runningProcess => runningProcess.MainWindowTitle.Contains("ExcelExport")))
                    {
                        runningProcess.Kill();
                    }
                    try
                    {
                        var diag = new SaveFileDialog()
                        {
                            Filter = "Excel文档 97-2003|*.xls|Excel文档 2007|*.xlsx",
                            FileName = "Excel文档.xlsx"
                        };
                        if (diag.ShowDialog() != DialogResult.OK) return;

                        ultraGridOptions.BeforeExport?.Invoke(exporter);
                        exporter.ExportAsync(grid, diag.FileName,
                            diag.FileName.ToLower().EndsWith(".xlsx")
                            ? Infragistics.Documents.Excel.WorkbookFormat.Excel2007
                            : Infragistics.Documents.Excel.WorkbookFormat.Excel97To2003);
                        ultraGridOptions.AfterExported?.Invoke(exporter);
                    }
                    catch (Exception ex)
                    {
                        MessageHelper.ShowErrorBox(ex.Message);
                    }
                };
            }

            if (ultraGridOptions.EnableExport || ultraGridOptions.EnableCopy)
                grid.ContextMenuStrip = menu;

            ApplyGridOptions(grid.DisplayLayout, ultraGridOptions);
        }

        public static void ApplyGridOptions(UltraGridLayout ultraGridLayout, UltraGridOptions ultraGridOptions)
        {
            if (ultraGridOptions.EnableFixedHeader)
            {
                ultraGridLayout.UseFixedHeaders = true;
                ultraGridLayout.Override.FixedCellSeparatorColor = Color.DarkRed;
            }

            if (ultraGridOptions.EnableFilter)
            {
                ultraGridLayout.Override.AllowRowFiltering = DefaultableBoolean.True;
                if (ultraGridOptions.FilterAboveOperand)
                {
                    ultraGridLayout.Override.FilterUIType = FilterUIType.FilterRow;
                    ultraGridLayout.Override.FilterOperandStyle = FilterOperandStyle.Edit;
                    ultraGridLayout.Override.FilterOperatorLocation = FilterOperatorLocation.AboveOperand;
                    ultraGridLayout.Override.FilterOperandDropDownItems = FilterOperandDropDownItems.All;
                    ultraGridLayout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.Equals;
                    ultraGridLayout.Override.FilterRowAppearance.BackColor = Color.LightYellow;
                }
            }

            if (ultraGridOptions.EnableAddNew)
            {
                ultraGridLayout.Override.TemplateAddRowSpacingBefore = 0;
                ultraGridLayout.Override.TemplateAddRowSpacingAfter = 0;
                ultraGridLayout.Override.SpecialRowSeparatorHeight = 3;
                ultraGridLayout.Override.AllowAddNew = AllowAddNew.FixedAddRowOnTop;
                ultraGridLayout.Override.AllowDelete = DefaultableBoolean.True;
                ultraGridLayout.Override.RowSizing = RowSizing.Fixed;
                ultraGridLayout.Override.ActiveCellBorderThickness = 0;
                ultraGridLayout.Override.TemplateAddRowAppearance.BackColor = Color.FromArgb(245, 250, 255);
                ultraGridLayout.Override.TemplateAddRowAppearance.ForeColor = SystemColors.GrayText;
                ultraGridLayout.Override.AddRowAppearance.BackColor = Color.LightYellow;
                ultraGridLayout.Override.AddRowAppearance.ForeColor = Color.Blue;
                ultraGridLayout.Override.SpecialRowSeparator = SpecialRowSeparator.TemplateAddRow;
                ultraGridLayout.Override.SpecialRowSeparatorAppearance.BackColor = SystemColors.Control;
                ultraGridLayout.Override.TemplateAddRowPrompt = "点击此处添加新的数据项，按【回车键】确认。";
                ultraGridLayout.Override.TemplateAddRowPromptAppearance.ForeColor = SystemColors.GrayText;
                ultraGridLayout.Override.TemplateAddRowPromptAppearance.FontData.Bold = DefaultableBoolean.True;
                ultraGridLayout.ScrollStyle = ScrollStyle.Immediate;
                ultraGridLayout.ScrollBounds = ScrollBounds.ScrollToFill;
                ultraGridLayout.Override.CellClickAction = CellClickAction.Edit;
            }
        }

        public static void InitializeUltraGridBandDisplay(UltraGridBand band, List<UltraGridDisplayItem> displayItems, UltraGridOptions ultraGridOptions = null)
        {
            // 整理顺序，保证连续
            int index = 1;
            int showOriginX = 0;
            int step = 2;
            foreach (var item in displayItems.Where(x => x.BandIndex == band.Index).OrderBy(x => x.Position))
            {
                if (!band.Columns.Exists(item.Key))
                    continue;

                var col = band.Columns[item.Key];
                col.Hidden = item.Hidden;
                col.Width = item.ColumnWidth;
                //col.Style = item.ColumnStyle;
                col.RowLayoutColumnInfo.SpanX = step;
                col.RowLayoutColumnInfo.SpanY = step;
                col.RowLayoutColumnInfo.OriginY = 0;
                // 设置表头高度
                col.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, ultraGridOptions?.RowColumnHeaderHeight ?? 30);
                col.Format = item.Format;

                col.Header.Caption = item.Caption;
                col.Header.VisiblePosition = index++;
                if (item.ForeColor != Color.Empty)
                    col.CellAppearance.ForeColor = item.ForeColor;
                if (item.BackColor != Color.Empty)
                    col.CellAppearance.BackColor = item.BackColor;
            }

            // 保证显示顺序和不增加额外的事件触发的同时，将不显示的列隐藏
            foreach (var item in band.Columns.Cast<UltraGridColumn>().OrderBy(x => x.Header.VisiblePosition))
            {
                if (!displayItems.Exists(x => x.Key.Equals(item.Key, StringComparison.OrdinalIgnoreCase) && x.BandIndex == band.Index))
                    item.Hidden = true;
            }
        }

        private static void SetDisplayLayout(UltraGridLayout ultraGridLayout, UltraGridOptions ultraGridOptions)
        {
            var colorBorder = Color.FromArgb(224, 224, 224);
            var colorBackground = Color.FromArgb(245, 245, 245);
            var colorForeground = Color.FromArgb(64, 64, 64);
            var colorWarning = Color.FromArgb(242, 149, 85);

            // 可配置信息
            ultraGridLayout.Override.RowSelectors = ultraGridOptions.RowSelectors;
            ultraGridLayout.Override.RowSelectorWidth = ultraGridOptions.RowSelectorWidth;
            ultraGridLayout.Override.RowSelectorNumberStyle = ultraGridOptions.RowSelectorNumberStyle;
            ultraGridLayout.Override.RowSelectorHeaderStyle = ultraGridOptions.RowSelectorHeaderStyle;
            ultraGridLayout.Override.RowSelectorStyle = HeaderStyle.Standard;
            ultraGridLayout.Override.RowSelectorAppearance.BackColor = Color.Transparent;
            ultraGridLayout.Override.RowSelectorAppearance.ForeColor = colorForeground;
            ultraGridLayout.Override.RowSelectorAppearance.TextHAlign = HAlign.Center;
            ultraGridLayout.Override.RowSelectorAppearance.TextVAlign = VAlign.Middle;
            ultraGridLayout.Override.RowSelectorAppearance.BorderColor = colorBorder;

            // 设置滚动条出现的时候不拆分
            ultraGridLayout.Appearance.FontData.SizeInPoints = 10;
            ultraGridLayout.MaxColScrollRegions = 1;
            ultraGridLayout.MaxRowScrollRegions = 1;
            //grid.DisplayLayout.ScrollBarLook.VerticalScrollBarWidth = 50;
            //grid.DisplayLayout.ScrollBarLook.VerticalScrollBarArrowHeight = 70;
            //grid.DisplayLayout.ScrollBarLook.MinimumThumbHeight = 70;

            ultraGridLayout.Appearance.BackColor = Color.White;
            ultraGridLayout.Appearance.BackColor2 = Color.FromArgb(177, 192, 214);
            ultraGridLayout.Appearance.BackGradientStyle = GradientStyle.BackwardDiagonal;
            ultraGridLayout.BorderStyle = UIElementBorderStyle.Solid;
            ultraGridLayout.ScrollBounds = ScrollBounds.ScrollToFill;
            ultraGridLayout.ScrollStyle = ScrollStyle.Immediate;
            ultraGridLayout.ViewStyle = ViewStyle.SingleBand;

            ultraGridLayout.DefaultSelectedBackColor = Color.Transparent;
            ultraGridLayout.DefaultSelectedForeColor = Color.Transparent;

            ultraGridLayout.NoDataSourceMessageEnabled = DefaultableBoolean.True;
            ultraGridLayout.NoDataSourceMessageAppearance.ForeColor = colorWarning;
            ultraGridLayout.NoDataSourceMessageAppearance.TextHAlign = HAlign.Center;
            ultraGridLayout.NoDataSourceMessageAppearance.TextVAlign = VAlign.Middle;

            //grid.DisplayLayout.CaptionVisible = DefaultableBoolean.False;
            ultraGridLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
            ultraGridLayout.Override.AllowColSizing = AllowColSizing.Synchronized;
            ultraGridLayout.Override.RowAppearance.BorderColor = colorBorder;
            ultraGridLayout.Override.CellAppearance.BorderColor = Color.Transparent;
            ultraGridLayout.Override.CellPadding = 0;
            ultraGridLayout.Override.DefaultRowHeight = ultraGridOptions?.RowHeight ?? 30;

            ultraGridLayout.Override.HeaderStyle = HeaderStyle.Standard;
            ultraGridLayout.Override.HeaderAppearance.BackColor = colorBackground;
            ultraGridLayout.Override.HeaderAppearance.ForeColor = colorForeground;
            ultraGridLayout.Override.HeaderAppearance.TextHAlign = HAlign.Center;
            ultraGridLayout.Override.HeaderAppearance.TextVAlign = VAlign.Middle;
            ultraGridLayout.Override.HeaderClickAction = ultraGridOptions.HeaderClickAction;

            ultraGridLayout.Override.SelectTypeGroupByRow = SelectType.None;
            ultraGridLayout.Override.SelectTypeRow = SelectType.None;

            ultraGridLayout.Override.BorderStyleRow = UIElementBorderStyle.WindowsVista;
            ultraGridLayout.Override.BorderStyleRowSelector = UIElementBorderStyle.WindowsVista;
            ultraGridLayout.Override.BorderStyleHeader = UIElementBorderStyle.Solid;
            ultraGridLayout.Override.BorderStyleCell = UIElementBorderStyle.None;

            ultraGridLayout.Override.ActiveAppearancesEnabled = DefaultableBoolean.True;
            ultraGridLayout.Override.ActiveRowAppearance.BackColor = colorBackground;
            ultraGridLayout.Override.ActiveRowAppearance.FontData.Bold = DefaultableBoolean.True;

            ultraGridLayout.Override.SelectedAppearancesEnabled = DefaultableBoolean.True;
            ultraGridLayout.Override.SelectedCellAppearance.BackColor = colorBackground;
            ultraGridLayout.Override.SelectedCellAppearance.FontData.Bold = DefaultableBoolean.True;

            //ultraGridLayout.Override.CellAppearance.BorderColor = colorBackground;
            ultraGridLayout.Override.CellAppearance.TextTrimming = TextTrimming.EllipsisCharacter;
            ultraGridLayout.Override.CellAppearance.TextHAlign = HAlign.Center;
            ultraGridLayout.Override.CellAppearance.TextVAlign = VAlign.Middle;
            ultraGridLayout.Override.CellClickAction = CellClickAction.RowSelect;
            ultraGridLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.Copy;
            // 点击例如超链接类的单元格时是否先获取焦点
            ultraGridLayout.CellHottrackInvalidationStyle = CellHottrackInvalidationStyle.Never;
            // 单元格获取焦点后的单元格边框粗细
            ultraGridLayout.Override.ActiveCellBorderThickness = 0;

            ultraGridLayout.RowSelectorImages.DataChangedImage = null;
        }

        private static void SetGridDefaultStyle(UltraGrid grid, UltraGridOptions ultraGridOptions)
        {
            SetDisplayLayout(grid.DisplayLayout, ultraGridOptions);

            grid.DisplayLayout.NoDataSourceMessageText = "列表没有绑定任何数据";
            foreach (var item in grid.DisplayLayout.Bands)
            {
                item.Override.AllowUpdate = ultraGridOptions.AllowUpdate;
                SetGridBandDefaultStyle(item);
            }
        }

        private static void SetGridBandDefaultStyle(UltraGridBand band)
        {
            var colorWarning = Color.FromArgb(242, 149, 85);
            // 调整默认行高信息
            band.Override.DefaultRowHeight = 30;
            band.Override.RowSizing = RowSizing.Fixed;
            band.Override.NoRowsInDataSourceMessageAppearance.ForeColor = colorWarning;
            band.Override.NoRowsInDataSourceMessageAppearance.TextHAlign = HAlign.Center;
            band.Override.NoRowsInDataSourceMessageAppearance.TextVAlign = VAlign.Middle;

            band.Override.NoRowsInDataSourceMessageEnabled = DefaultableBoolean.True;
            band.Override.NoRowsInDataSourceMessageText = "没有找到任何数据";

            band.Override.NoVisibleRowsMessageAppearance.ForeColor = colorWarning;
            band.Override.NoVisibleRowsMessageAppearance.TextHAlign = HAlign.Center;
            band.Override.NoVisibleRowsMessageAppearance.TextVAlign = VAlign.Middle;
            band.Override.NoVisibleRowsMessageEnabled = DefaultableBoolean.True;
            band.Override.NoVisibleRowsMessageText = "没有匹配到任何记录";

            band.RowLayoutStyle = RowLayoutStyle.ColumnLayout;
        }

        /// <summary>
        /// 此方法在 <see cref="UltraGrid" /> 的 InitializeRow 事件下调用
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="caption">列标题</param>
        /// <param name="clickAction">点击链接后的事件处理</param>
        /// <param name="defaultValue">要添加的按钮</param>
        /// <param name="linkedColumn">添加的超链接列</param>
        public static UltraGridColumn AddLinkedColumn(UltraGrid grid,
            string caption,
            Infragistics.Win.FormattedLinkLabel.LinkClickedEventHandler clickAction,
            List<UltraGridDisplayItem> defaultValue = null!,
            Action<UltraGridColumn> linkedColumn = null!)
        {
            return grid.DisplayLayout.Bands[0].AddLinkedColumn(caption, clickAction, defaultValue, gridColumn =>
            {
                linkedColumn?.Invoke(gridColumn);
            });
        }

        public static List<UltraGridColumn> AddLinkedColumns(UltraGrid grid,
            string caption,
            Infragistics.Win.FormattedLinkLabel.LinkClickedEventHandler clickAction,
            List<UltraGridDisplayItem> defaultValue = null!,
            Action<UltraGridColumn> linkedColumn = null!)
        {
            var columns = new List<UltraGridColumn>();
            foreach (var item in grid.DisplayLayout.Bands)
            {
                columns.Add(item.AddLinkedColumn(caption, clickAction, defaultValue, gridColumn =>
                {
                    linkedColumn?.Invoke(gridColumn);
                }));
            }
            return columns;
        }

        /// <summary>
        /// 动态添加列 使用此方法初始化列后，需要给该列赋值时，需要配合InitializeRow事件来做赋值
        /// </summary>
        /// <param name="band">band</param>
        /// <param name="key">key</param>
        /// <param name="caption">列标题</param>
        /// <param name="type">列类型</param>
        /// <param name="foreColor">颜色</param>
        /// <param name="hAlign">水平对齐方式</param>
        /// <param name="vAlign">垂直对齐方式</param>
        /// <returns></returns>
        public static UltraGridColumn AddUnBoundColumn(UltraGrid grid,
               string key,
               string caption,
               Infragistics.Win.UltraWinGrid.ColumnStyle type,
               string defaultValue = "",
               AppearanceBase cellAppearance = null!,
               AppearanceBase headerAppearance = null
               )
        {
            return grid.AddUnBoundColumn(key, caption, type, defaultValue, cellAppearance, headerAppearance);
        }
    }

    public class DisplayItem
    {
        public string Key { get; set; }

        public string Caption { get; set; }

        public double Position { get; set; }

        /// <summary>
        /// 是否隐藏
        /// </summary>
        public bool Hidden { get; set; }

        public override string ToString()
        {
            return Caption;
        }
    }

    public class DisplayItemComparer : IEqualityComparer<DisplayItem>
    {
        public bool Equals(DisplayItem x, DisplayItem y)
        {
            return string.Compare(x.Key, y.Key, true) == 0;
        }

        public int GetHashCode(DisplayItem obj)
        {
            return obj.Key.GetHashCode();
        }
    }

    public class UltraGridDisplayItem : DisplayItem
    {
        public int BandIndex { get; set; } = 0;

        /// <summary>
        /// 列颜色,空值为默认
        /// </summary>
        public System.Drawing.Color ForeColor { get; set; }

        /// <summary>
        /// 列颜色,空值为默认
        /// </summary>
        public System.Drawing.Color BackColor { get; set; }

        public string? Format { get; set; }

        /// <summary>
        /// 列样式,空值为默认
        /// </summary>
        public Infragistics.Win.UltraWinGrid.ColumnStyle ColumnStyle { get; set; } = Infragistics.Win.UltraWinGrid.ColumnStyle.Default;

        public int ColumnWidth { get; set; } = 120;
    }

    public class UltraGridOptions
    {
        /// <summary>
        /// 是否显示列序号
        /// </summary>
        public Infragistics.Win.DefaultableBoolean RowSelectors { get; set; } = DefaultableBoolean.True;

        /// <summary>
        /// 列序号宽度
        /// </summary>
        public int RowSelectorWidth { get; set; } = 60;

        public int RowColumnHeaderHeight { get; set; } = 30;

        public int RowHeight { get; set; } = 30;

        public RowSelectorNumberStyle RowSelectorNumberStyle { get; set; } = RowSelectorNumberStyle.VisibleIndex;

        public RowSelectorHeaderStyle RowSelectorHeaderStyle { get; set; } = RowSelectorHeaderStyle.SeparateElement;

        /// <summary>
        /// 是否允许更新grid
        /// </summary>
        public DefaultableBoolean AllowUpdate { get; set; } = DefaultableBoolean.False;

        /// <summary>
        /// 是否显示概要
        /// </summary>
        public bool ShowSummary { get; set; }

        /// <summary>
        /// 概要占的行数
        /// </summary>
        public int ShowSummaryLines { get; set; } = 1;

        /// <summary>
        /// 点击表头是否可以排序
        /// </summary>
        public HeaderClickAction HeaderClickAction { get; set; } = HeaderClickAction.SortSingle;

        /// <summary>
        /// 是否启用列冻结
        /// </summary>
        public bool EnableFixedHeader { get; set; }

        /// <summary>
        /// 是否启用行筛选
        /// </summary>
        public bool EnableFilter { get; set; }

        /// <summary>
        /// 筛选方式在首行,而不是筛选图标
        /// </summary>
        public bool FilterAboveOperand { get; set; }

        public bool EnableAddNew { get; set; }

        /// <summary>
        /// 是否启用导出，需要注意的是启用导出后，不能同时在同一个Grid上再次绑定GridExporter，否则可能会导致另一个GridExporter触发BUG
        /// </summary>
        public bool EnableExport { get; set; }

        public bool ExportValueList { get; set; } = true;

        public bool ExportFormula { get; set; } = true;

        public bool EnableCopy { get; set; } = true;

        public BeforeExport BeforeExport { get; set; }

        public AfterExported AfterExported { get; set; }

        public InitialExport InitialExport { get; set; }
    }

    public delegate void InitialExport(Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ultraGridExcelExporter);

    public delegate void BeforeExport(Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ultraGridExcelExporter);

    public delegate void AfterExported(Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ultraGridExcelExporter);
}